package abcy.cloud.syscoreserver.exception.handler;

import abcy.cloud.syscoreserver.exception.NotEmptyException;
import abcy.cloud.syscoreserver.exception.model.ErrorResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = NotEmptyException.class)
    public ResponseEntity<Object> handleUserNotFoundException(NotEmptyException ex) {
        // 返回一个自定义的错误响应
        ErrorResponse errorResponse = new ErrorResponse(
                ex.getErrorCode(),
                "User Not Found",
                ex.getMessage()
        );
        return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND);
    }

    // 可以添加更多的异常处理器方法
}